package com.gmail.dengtao.joe.commons.crypto.mac;

import java.security.NoSuchAlgorithmException;

import javax.crypto.Mac;

/**
 * Mac constants.
 * @author <a href="mailto:joe.dengtao@gmail.com">DengTao</a>
 * @version 1.0
 * @since 1.0
 */
class MacUtils {
	
	/** The MD5 Hash Message Authentication Code algorithm defined in RFC 2403. */
	public static final String HMAC_MD5 = "HmacMD5";
	/** The SHA-1 Hash Message Authentication Code algorithm. */
	public static final String HMAC_SHA_1 = "HmacSHA1";
	/** The SHA-256 Hash Message Authentication Code algorithm. */
	public static final String HMAC_SHA_256 = "HmacSHA256";
	public static final String HMAC_SHA_384 = "HmacSHA384";
	public static final String HMAC_SHA_512 = "HmacSHA512";
	
	/**
     * Returns a Mac object that implements the specified MAC algorithm. 
     *
     * @param algorithm
     *            the name of the algorithm requested. See <a
     *            href="http://java.sun.com/j2se/1.3/docs/guide/security/CryptoSpec.html#AppA">Appendix A in the Java
     *            Cryptography Architecture API Specification & Reference</a> for information about standard algorithm
     *            names.
     * @return An Mac instance.
     * @see Mac#getInstance(String)
     * @throws IllegalArgumentException
     *             when a {@link NoSuchAlgorithmException} is caught.
     */
    public static Mac getMac(String algorithm) {
        try {
            return Mac.getInstance(algorithm);
        } catch (NoSuchAlgorithmException e) {
            throw new IllegalArgumentException(e);
        }
    }
    
}
